package org.javaforever.gatescore.shiroauth.vue;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.javaforever.gatescore.core.FrontDomain;
import org.javaforever.gatescore.core.FrontDropdown;
import org.javaforever.gatescore.core.FrontField;
import org.javaforever.gatescore.core.FrontMethod;
import org.javaforever.gatescore.core.FrontVar;
import org.javaforever.gatescore.core.Statement;
import org.javaforever.gatescore.core.StatementList;
import org.javaforever.gatescore.core.UtilsMethodGenerator;
import org.javaforever.gatescore.core.Writeable;
import org.javaforever.gatescore.core.WriteableUtil;
import org.javaforever.gatescore.exception.ValidateException;
import org.javaforever.gatescore.vue.ElementUIPage;

public class ElementUIRegisterUserPage extends ElementUIPage {
	private static final long serialVersionUID = -2649592707352006379L;
	protected String stanadardName;
	protected String language = "chinese";
	protected FrontDomain domain;
	protected String title;
	protected Set<FrontField> deniedFields = new TreeSet<>();

	public String getStanadardName() {
		return stanadardName;
	}

	public void setStanadardName(String stanadardName) {
		this.stanadardName = stanadardName;
	}

	@Override
	public StatementList generateStatementList() throws Exception{
		Set<FrontField> deniedFields = new TreeSet<>();
		deniedFields.add(this.domain.findFieldByFixedName("salt"));
		deniedFields.add(this.domain.findFieldByFixedName("loginFailure"));
		deniedFields.add(this.domain.findFieldByFixedName("password"));
		this.deniedFields = deniedFields;
		
		List<Writeable> sList = new ArrayList<Writeable>();
		sList.add(new Statement(500L,0,"<template>"));
		sList.add(new Statement(1000L,1,"<div class=\"app-container\" style=\"text-align:center\">"));
		sList.add(new Statement(2000L,2,"<div><h2>"+this.title+"</h2></div>"));
		sList.add(new Statement(3000L,2,"<div style=\"width:800px;text-align:center;margin-left:250px\">"));
		long serial = 4000L;
		sList.add(new Statement(serial,3,"<el-form :model=\"form\" label-position=\"right\" label-width=\"120px\">"));
		sList.add(new Statement(serial+1000L,4,"<el-row>"));
		
		serial += 2000L;		
		sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
		sList.add(new Statement(serial+1000L,6,"<el-form-item label=\""+this.domain.getDomainName().getText()+"\">"));
		sList.add(new Statement(serial+2000L,7,"<el-input v-model=\"form."+this.domain.getDomainName().getFieldName()+"\" style=\"width: 240px;\"/>"));
		sList.add(new Statement(serial+3000L,6,"</el-form-item>"));
		sList.add(new Statement(serial+4000L,5,"</el-col>"));
		
		serial += 5000L;
		sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
		sList.add(new Statement(serial+1000L,6,"<el-form-item label=\""+this.domain.getActive().getText()+"\">"));
		sList.add(new Statement(serial+2000L,7,"<el-input v-model=\"form."+this.domain.getActive().getFieldName()+"\" style=\"width: 240px;\"/>"));
		sList.add(new Statement(serial+3000L,6,"</el-form-item>"));
		sList.add(new Statement(serial+4000L,5,"</el-col>"));

		serial += 5000L;
		FrontField f0 = this.domain.findFieldByFixedName("password");
		sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
		sList.add(new Statement(serial+1000L,6,"<el-form-item label=\""+f0.getText()+"\">"));
		sList.add(new Statement(serial+2000L,7,"<el-input v-model=\"form."+f0.getFieldName()+"\" type=\"password\" style=\"width: 240px;\"/>"));
		sList.add(new Statement(serial+3000L,6,"</el-form-item>"));
		sList.add(new Statement(serial+4000L,5,"</el-col>"));
		
		serial += 5000L;
		sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
		if ("english".equalsIgnoreCase(this.domain.getLanguage())) {
			sList.add(new Statement(serial+1000L,6,"<el-form-item label=\"Confirm "+f0.getText()+"\">"));
		}else {
			sList.add(new Statement(serial+1000L,6,"<el-form-item label=\"确认"+f0.getText()+"\">"));
		}
		sList.add(new Statement(serial+2000L,7,"<el-input v-model=\"form.confirm"+f0.getCapFirstFieldName()+"\" type=\"password\" style=\"width: 240px;\"/>"));
		sList.add(new Statement(serial+3000L,6,"</el-form-item>"));
		sList.add(new Statement(serial+4000L,5,"</el-col>"));
		
		serial = serial + 6000L;
		for (FrontField f:this.domain.getPlainFields()) {
			if (!this.deniedFields.contains(f)) {
				if (!(f instanceof FrontDropdown)) {
					if (f.getFieldType().getTypeName().equalsIgnoreCase("image")) {
						sList.add(new Statement(serial+1000L,5,"<el-col :span=\"12\">"));
						sList.add(new Statement(serial+2000L,6,"<el-form-item label=\""+f.getText()+"\">"));
						sList.add(new Statement(serial+3000L,7,"<el-upload"));
						sList.add(new Statement(serial+4000L,8,":action=\"this.loginBaseApi+'login"+this.domain.getControllerNamingSuffix()+"/addUpload"+this.domain.getCapFirstDomainName()+f.getCapFirstFieldName()+"'\""));
						sList.add(new Statement(serial+5000L,8,":show-file-list=\"false\""));
						sList.add(new Statement(serial+6000L,8,":on-success=\"handle"+this.domain.getCapFirstDomainName()+f.getCapFirstFieldName()+"ImageSuccess\""));
						sList.add(new Statement(serial+7000L,8,":before-upload=\"before"+this.domain.getCapFirstDomainName()+f.getCapFirstFieldName()+"ImageUpload\""));
						sList.add(new Statement(serial+7500L,8,"name=\"files[]\">"));
						sList.add(new Statement(serial+8000L,8,"<img v-if=\""+f.getLowerFirstFieldName()+"ImageUrl\" :src=\""+f.getLowerFirstFieldName()+"ImageUrl\" width=\"300\">"));
						sList.add(new Statement(serial+9000L,8,"<img v-else :src=\"'../static/images/blank.jpg'\" width=\"300\">"));
						sList.add(new Statement(serial+10000L,8,"<br>"));
						if (this.domain.getLanguage().equalsIgnoreCase("english")) {
							sList.add(new Statement(serial+11000L,8,"<el-button type=\"primary\" plain @click=\"up"+this.domain.getCapFirstDomainName()+f.getCapFirstFieldName()+"ImageData\">Upload</el-button>"));
						}else {
							sList.add(new Statement(serial+11000L,8,"<el-button type=\"primary\" plain @click=\"up"+this.domain.getCapFirstDomainName()+f.getCapFirstFieldName()+"ImageData\">上传</el-button>"));
						}
						sList.add(new Statement(serial+12000L,7,"</el-upload>"));
						sList.add(new Statement(serial+13000L,6,"</el-form-item>"));
						sList.add(new Statement(serial+14000L,5,"</el-col>"));
					} else if (f.getFieldType().getTypeName().equalsIgnoreCase("datetime")) {
						sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
						sList.add(new Statement(serial+500L,6,"<el-form-item label=\""+f.getText()+"\">"));						
						sList.add(new Statement(serial+1000L,7,"<el-date-picker"));
						sList.add(new Statement(serial+2000L,8,"v-model=\"form."+f.getLowerFirstFieldName()+"\""));
						sList.add(new Statement(serial+3000L,8,"value-format=\"yyyy-MM-dd HH:mm:ss\""));
						sList.add(new Statement(serial+4000L,8,"type=\"datetime\""));
						sList.add(new Statement(serial+5000L,8,"style=\"width: 160px\""));
						sList.add(new Statement(serial+6000L,8,"placeholder=\"选择"+f.getText()+"\""));
						sList.add(new Statement(serial+7000L,8,"label=\""+f.getText()+"\""));
						sList.add(new Statement(serial+8000L,7,"/>"));
						sList.add(new Statement(serial+10000L,6,"</el-form-item>"));
						sList.add(new Statement(serial+11000L,5,"</el-col>"));
					} else if (f.getFieldType().getTypeName().equalsIgnoreCase("date")) {
						sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
						sList.add(new Statement(serial+500L,6,"<el-form-item label=\""+f.getText()+"\">"));	
						sList.add(new Statement(serial+1000L,7,"<el-date-picker"));
						sList.add(new Statement(serial+2000L,8,"v-model=\"form."+f.getLowerFirstFieldName()+"\""));
						sList.add(new Statement(serial+3000L,8,"value-format=\"yyyy-MM-dd\""));						
						sList.add(new Statement(serial+4000L,8,"type=\"date\""));
						sList.add(new Statement(serial+5000L,8,"style=\"width: 160px\""));
						sList.add(new Statement(serial+6000L,8,"placeholder=\"选择"+f.getText()+"\""));
						sList.add(new Statement(serial+7000L,8,"label=\""+f.getText()+"\""));
						sList.add(new Statement(serial+8000L,7,"/>"));
						sList.add(new Statement(serial+10000L,6,"</el-form-item>"));
						sList.add(new Statement(serial+11000L,5,"</el-col>"));
					} else {
						sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
						sList.add(new Statement(serial+1000L,6,"<el-form-item label=\""+f.getText()+"\">"));
						sList.add(new Statement(serial+2000L,7,"<el-input v-model=\"form."+f.getFieldName()+"\" style=\"width: 240px;\"/>"));
						sList.add(new Statement(serial+3000L,6,"</el-form-item>"));
						sList.add(new Statement(serial+4000L,5,"</el-col>"));
					}
					serial = serial + 15000L;
				}else {
					FrontDropdown dp = (FrontDropdown)f;
					sList.add(new Statement(serial,5,"<el-col :span=\"12\">"));
					sList.add(new Statement(serial+1000L,6,"<el-form-item label=\""+dp.getText()+"\" prop=\""+dp.getAliasOrName()+"\">"));
					if (this.domain.getLanguage().equalsIgnoreCase("english")) {
						sList.add(new Statement(serial+2000L,7,"<el-select v-model=\"form."+dp.getAliasName()+"\" value-key=\""+dp.getTarget().getDomainId().getFieldName()+"\" placeholder=\"Please choose \" style=\"width: 240px;\" @change=\"translate"+dp.getTarget().getCapFirstDomainName()+"\">"));
					}else{
						sList.add(new Statement(serial+2000L,7,"<el-select v-model=\"form."+dp.getAliasName()+"\" value-key=\""+dp.getTarget().getDomainId().getFieldName()+"\" placeholder=\"请选择\" style=\"width: 240px;\" @change=\"translate"+dp.getTarget().getCapFirstDomainName()+"\">"));
					}
					sList.add(new Statement(serial+2500L,8,"<el-option key=\""+dp.getAliasName()+"\" label=\"---\" value=\"-1\"/>"));
					sList.add(new Statement(serial+3000L,8,"<el-option"));
					sList.add(new Statement(serial+4000L,9,"v-for=\"item in active"+dp.getTarget().getCapFirstPlural()+"\""));
					sList.add(new Statement(serial+5000L,9,":key=\"item."+dp.getAliasName()+"\""));
					sList.add(new Statement(serial+6000L,9,":label=\"item."+dp.getTarget().getDomainName().getFieldName()+"\""));
					sList.add(new Statement(serial+7000L,9,":value=\"item."+dp.getTarget().getDomainId().getFieldName()+"\"/>"));
					sList.add(new Statement(serial+9000L,7,"</el-select>"));
					sList.add(new Statement(serial+10000L,6,"</el-form-item>"));
					sList.add(new Statement(serial+11000L,5,"</el-col>"));
					serial = serial + 15000L;
				}	
			}
		}
		sList.add(new Statement(serial,4,"</el-row>"));
		sList.add(new Statement(serial+1000L,3,"</el-form>"));
		sList.add(new Statement(serial+2000L,3,"<span slot=\"footer\" class=\"dialog-footer\">"));
		if (this.domain.getLanguage().equalsIgnoreCase("english")) {
			sList.add(new Statement(serial+3000L,4,"<el-button @click=\"handleLogin\">Back to Login</el-button>"));
			sList.add(new Statement(serial+4000L,4,"<el-button type=\"primary\" @click=\"register"+this.domain.getCapFirstDomainName()+"\">Register</el-button>"));
			sList.add(new Statement(serial+4500L,4,"<el-button @click=\"resetForm\">Reset</el-button>"));
		}else {
			sList.add(new Statement(serial+3000L,4,"<el-button @click=\"handleLogin\">回到登录</el-button>"));
			sList.add(new Statement(serial+4000L,4,"<el-button type=\"primary\" @click=\"register"+this.domain.getCapFirstDomainName()+"\">注 册</el-button>"));
			sList.add(new Statement(serial+4500L,4,"<el-button @click=\"resetForm\">重 置</el-button>"));
		}
		sList.add(new Statement(serial+5000L,3,"</span>"));
		sList.add(new Statement(serial+10000L,2,"</div>"));
		sList.add(new Statement(serial+11000L,1,"</div>"));
		sList.add(new Statement(serial+12000L,0,"</template>"));

		sList.add(new Statement(serial+12500L,0,"<script>"));
		sList.add(new Statement(serial+13000L,0,"import {"));
		sList.add(new Statement(serial+14000L,1,"register"+this.domain.getCapFirstDomainName()+""));
		sList.add(new Statement(serial+15000L,0,"} from '@/api/login'"));
	
		serial += 17000L;
		
		Set<FrontDomain> dpDomains = new TreeSet<FrontDomain>();
		FrontVar defaultForm = new FrontVar("defaultForm");
		FrontVar pagevars = new FrontVar("pagevars");
		for (FrontField ff:this.domain.getAllFieldsWithoutId()) {
			if (ff instanceof FrontDropdown) {
				FrontDropdown dp = (FrontDropdown) ff;
				dpDomains.add(dp.getTarget());
			}
		}
		
		for (FrontDomain d:dpDomains) {
			sList.add(new Statement(serial,0,"import {"));
			sList.add(new Statement(serial+1000L,1,"listActive"+d.getCapFirstPlural()+""));
			sList.add(new Statement(serial+2000L,0,"} from '@/api/login'"));
			serial += 3000L;
		}
		
		sList.add(new Statement(serial,0,""));
		sList.add(new Statement(serial+1000L,0,"import pagevars from '@/pagevars'"));		
		sList.add(new Statement(serial+16500L,0,"import sha1 from 'sha1'"));
		
		Set<FrontField> deniedFields2 = new TreeSet<>();
		deniedFields2.add(this.domain.findFieldByFixedName("salt"));
		deniedFields2.add(this.domain.findFieldByFixedName("loginFailure"));
		
		StatementList sl = UtilsMethodGenerator.generateDefaultFormBlockStatementsWithoutDeniedFields(this.domain, deniedFields2,defaultForm);
		sl.setSerial(serial+17000L);
		sList.add(sl); 
		
		sList.add(new Statement(serial+38000L,0,"export function isBlank(val) {"));
		sList.add(new Statement(serial+39000L,1,"if (val === undefined || val === null || val === '') return true"));
		sList.add(new Statement(serial+40000L,1,"else return false"));
		sList.add(new Statement(serial+41000L,0,"}"));
		sList.add(new Statement(serial+42000L,0,""));
		
		
		sList.add(new Statement(serial+43000L,0,"export default {"));
		sList.add(new Statement(serial+44000L,1,"inject: ['reload'],"));
		
		sList.add(new Statement(serial+45000L,1,"filters: {"));
		serial += 46000L;
		for (FrontDomain d:dpDomains) {
			sl = UtilsMethodGenerator.generateDomainFilterStatements(d, pagevars);
			sl.setSerial(serial);
			sl.setIndent(1);
			sList.add(sl); 	
			serial += 1000L;
		}
		sList.add(new Statement(serial,1,"},"));
		
		sl = UtilsMethodGenerator.generateDataBlockStatementsForRegister(domain, defaultForm, pagevars, dpDomains);
		sl.setSerial(serial+44000L);
		sl.setIndent(1);
		sList.add(sl);
		
		sl = UtilsMethodGenerator.generateRegisterUserCreatedBlockStatements(dpDomains);
		sl.setSerial(serial+46000L);
		sl.setIndent(1);
		sList.add(sl);

		sList.add(new Statement(serial+53000L,1,"methods: {"));
		sList.add(new Statement(serial+54000L,2,"handleLogin() {"));
		sList.add(new Statement(serial+55000L,3,"this.$router.push({ path: '/login' })"));
		sList.add(new Statement(serial+56000L,2,"},"));
		sList.add(new Statement(serial+57000L,2,"resetForm() {"));
		sList.add(new Statement(serial+58000L,3,"this.form = {}"));
		sList.add(new Statement(serial+59000L,2,"},"));
		
		serial += 60000L;
		for (FrontField f: domain.getFields()) {
			if (!this.deniedFields.contains(f)) {
				if (f.getFieldType()!=null&&f.getFieldType().getTypeName()!=null&&"image".equalsIgnoreCase(f.getFieldType().getTypeName())) {
					sl = UtilsMethodGenerator.generateHandleImageSuccessMethodStatements(domain, f);
						sl.setSerial(serial);
						sList.add(sl);
						sl = UtilsMethodGenerator.generateBeforeImageUploadsMethodStatements(domain, f);
						sl.setSerial(serial+1000L);
						sList.add(sl);
						sl = UtilsMethodGenerator.generateUpImageDataMethodStatements(domain, f);
						sl.setSerial(serial+2000L);
						sList.add(sl);
						serial+= 3000L;
				}	
			}
		}
		
		sl = UtilsMethodGenerator.generateParseBooleanMethodStatements();
		sl.setSerial(serial);
		sList.add(sl);	
		
		sl = UtilsMethodGenerator.generateParseBooleanIntMethodStatements();
		sl.setSerial(serial+500L);
		sList.add(sl);	
		
		sl = UtilsMethodGenerator.generateParseIntNegMethodStatements();
		sl.setSerial(serial+800L);
		sList.add(sl);	
		
		sList.add(new Statement(serial+1000L,2,"register"+this.domain.getCapFirstDomainName()+"() {"));
		sList.add(new Statement(serial+2000L,3,"var data = this.form"));

		if ("english".equalsIgnoreCase(this.domain.getLanguage())) {
			sList.add(new Statement(serial+4000L,3,"if (isBlank(data."+this.domain.findFieldByFixedName("userName").getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+5000L,4,"this.$message.error(\""+this.domain.findFieldByFixedName("userName").getText()+" can not be empty.\")"));
			sList.add(new Statement(serial+5500L,4,"return"));
			sList.add(new Statement(serial+6000L,3,"}"));
			sList.add(new Statement(serial+7000L,3,"if (isBlank(data."+this.domain.getActive().getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+8000L,4,"this.$message.error(\""+this.domain.getActive().getText()+" field can not be empty.\")"));
			sList.add(new Statement(serial+8500L,4,"return"));
			sList.add(new Statement(serial+9000L,3,"}"));
			sList.add(new Statement(serial+10000L,3,"if (isBlank(data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+11000L,4,"this.$message.error(\""+this.domain.findFieldByFixedName("password").getText()+" can not be empty.\")"));
			sList.add(new Statement(serial+11500L,4,"return"));
			sList.add(new Statement(serial+12000L,3,"}"));
			sList.add(new Statement(serial+13000L,3,"if (data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+" !== data.confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+") {"));
			sList.add(new Statement(serial+14000L,4,"this.$message.error(\""+this.domain.findFieldByFixedName("password").getText()+" does not match.\")"));
			sList.add(new Statement(serial+14500L,4,"return"));
			sList.add(new Statement(serial+15000L,3,"}"));
			
			sList.add(new Statement(serial+15500L,3,"var "+this.domain.getLowerFirstDomainName()+" = Object.assign({}, data)"));
						
			if ("oracle".equalsIgnoreCase(this.domain.getDbType())&&!"simple".equalsIgnoreCase(this.domain.getTechnicalstack())&&!"tower".equalsIgnoreCase(this.domain.getTechnicalstack())) {
				sList.add(new Statement(serial+16000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.getActive().getLowerFirstFieldName()+" = this.parseBooleanInt(data."+this.domain.getActive().getLowerFirstFieldName()+")"));
			} else {
				sList.add(new Statement(serial+16000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.getActive().getLowerFirstFieldName()+" = this.parseBoolean(data."+this.domain.getActive().getLowerFirstFieldName()+")"));
			}
			sList.add(new Statement(serial+17000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+" = sha1(data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+")"));
			sList.add(new Statement(serial+18000L,3,this.domain.getLowerFirstDomainName()+".confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+" = sha1(data.confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+")"));
		} else {
			sList.add(new Statement(serial+4000L,3,"if (isBlank(data."+this.domain.findFieldByFixedName("userName").getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+5000L,4,"this.$message.error('"+this.domain.findFieldByFixedName("userName").getText()+"不可为空！')"));
			sList.add(new Statement(serial+5500L,4,"return"));
			sList.add(new Statement(serial+6000L,3,"}"));
			sList.add(new Statement(serial+7000L,3,"if (isBlank(data."+this.domain.getActive().getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+8000L,4,"this.$message.error('"+this.domain.getActive().getText()+"不可为空！')"));
			sList.add(new Statement(serial+8500L,4,"return"));
			sList.add(new Statement(serial+9000L,3,"}"));
			sList.add(new Statement(serial+10000L,3,"if (isBlank(data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+")) {"));
			sList.add(new Statement(serial+11000L,4,"this.$message.error('"+this.domain.findFieldByFixedName("password").getText()+"不可为空！')"));
			sList.add(new Statement(serial+11500L,4,"return"));
			sList.add(new Statement(serial+12000L,3,"}"));
			sList.add(new Statement(serial+13000L,3,"if (data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+" !== data.confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+") {"));
			sList.add(new Statement(serial+14000L,4,"this.$message.error('"+this.domain.findFieldByFixedName("password").getText()+"不匹配！')"));
			sList.add(new Statement(serial+14500L,4,"return"));
			sList.add(new Statement(serial+15000L,3,"}"));
			
			sList.add(new Statement(serial+15500L,3,"var "+this.domain.getLowerFirstDomainName()+" = Object.assign({}, data)"));
			
			if ("oracle".equalsIgnoreCase(this.domain.getDbType())&&!"simple".equalsIgnoreCase(this.domain.getTechnicalstack())&&!"tower".equalsIgnoreCase(this.domain.getTechnicalstack())) {
				sList.add(new Statement(serial+16000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.getActive().getLowerFirstFieldName()+" = this.parseBooleanInt(data."+this.domain.getActive().getLowerFirstFieldName()+")"));
			} else {
				sList.add(new Statement(serial+16000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.getActive().getLowerFirstFieldName()+" = this.parseBoolean(data."+this.domain.getActive().getLowerFirstFieldName()+")"));
			}
			sList.add(new Statement(serial+17000L,3,this.domain.getLowerFirstDomainName()+"."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+" = sha1(data."+this.domain.findFieldByFixedName("password").getLowerFirstFieldName()+")"));
			sList.add(new Statement(serial+18000L,3,this.domain.getLowerFirstDomainName()+".confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+" = sha1(data.confirm"+this.domain.findFieldByFixedName("password").getCapFirstFieldName()+")"));
		}
		
		serial += 19000L;

		for (FrontField f: this.domain.getPlainFields()){
			if (!this.deniedFields.contains(f)) {
				if (f instanceof FrontDropdown) {
					sList.add(new Statement(serial, 3, this.domain.getLowerFirstDomainName()+"."+f.getLowerFirstFieldName() + " = parseInt(data."+f.getLowerFirstFieldName()+")"));
				} else if (f.getFieldType().getTypeName().equalsIgnoreCase("bool")||f.getFieldType().getTypeName().equalsIgnoreCase("boolean")) {
					if ("oracle".equalsIgnoreCase(this.domain.getDbType())&&!"go".equals(this.domain.getComputerLanguage())) {
						sList.add(new Statement(serial, 3,
								this.domain.getLowerFirstDomainName()+"."+f.getLowerFirstFieldName() +  " = this.parseBooleanInt(data."+f.getLowerFirstFieldName()+")"));
					}else {
						sList.add(new Statement(serial, 3,
								this.domain.getLowerFirstDomainName()+"."+f.getLowerFirstFieldName() +  " = this.parseBoolean(data."+f.getLowerFirstFieldName()+")"));
					}
				} else if (f.getFieldType().getTypeName().equalsIgnoreCase("int")||f.getFieldType().getTypeName().equalsIgnoreCase("Integer")||f.getFieldType().getTypeName().equalsIgnoreCase("long")||f.getFieldType().getTypeName().equalsIgnoreCase("int32")||f.getFieldType().getTypeName().equalsIgnoreCase("int64")||f.getFieldType().getTypeName().equalsIgnoreCase("i32")||f.getFieldType().getTypeName().equalsIgnoreCase("i64")) {
					sList.add(new Statement(serial, 3, this.domain.getLowerFirstDomainName()+"."+f.getLowerFirstFieldName() +  " = parseInt(data."+f.getLowerFirstFieldName()+")"));
				} else if (f.getFieldType().getTypeName().equalsIgnoreCase("float")||f.getFieldType().getTypeName().equalsIgnoreCase("double")||f.getFieldType().getTypeName().equalsIgnoreCase("float64")||f.getFieldType().getTypeName().equalsIgnoreCase("float32")||f.getFieldType().getTypeName().equalsIgnoreCase("f32")||f.getFieldType().getTypeName().equalsIgnoreCase("f64")) {
					sList.add(new Statement(serial, 3, this.domain.getLowerFirstDomainName()+"."+f.getLowerFirstFieldName() +" = parseFloat(data."+f.getLowerFirstFieldName()+")"));
				} else if (f instanceof FrontDropdown) {
					sList.add(new Statement(serial, 3, "data."+f.getLowerFirstFieldName()+" = this.parseIntNeg(data."+f.getLowerFirstFieldName()+")"));
				}
				serial += 1000;
			}
		}
		
		sList.add(new Statement(serial+78000L,3,"register"+this.domain.getCapFirstDomainName()+"("+this.domain.getLowerFirstDomainName()+").then(response => {"));
		if ("english".equalsIgnoreCase(this.domain.getLanguage())) {
			sList.add(new Statement(serial+78100L,4,"if (response.data.success === true) {"));
			sList.add(new Statement(serial+78200L,5,"this.$message.success('New account created.')"));
			sList.add(new Statement(serial+78300L,5,"this.reload()"));
			sList.add(new Statement(serial+78310L,4,"} else if (response.data.success === false) {"));
			sList.add(new Statement(serial+78320L,5,"this.$message.error(response.data.error)"));
			sList.add(new Statement(serial+78400L,4,"} else {"));
			sList.add(new Statement(serial+78500L,5,"this.$message.error('Register error.')"));
			sList.add(new Statement(serial+78600L,4,"}"));
		}else {
			sList.add(new Statement(serial+78100L,4,"if (response.data.success === true) {"));
			sList.add(new Statement(serial+78200L,5,"this.$message.success('成功创建新账号！')"));
			sList.add(new Statement(serial+78300L,5,"this.reload()"));
			sList.add(new Statement(serial+78310L,4,"} else if (response.data.success === false) {"));
			sList.add(new Statement(serial+78320L,5,"this.$message.error(response.data.error)"));
			sList.add(new Statement(serial+78400L,4,"} else {"));
			sList.add(new Statement(serial+78500L,5,"this.$message.error('注册账号失败！')"));
			sList.add(new Statement(serial+78600L,4,"}"));
		}
		sList.add(new Statement(serial+80000L,3,"})"));
		sList.add(new Statement(serial+81000L,2,"},"));
		
		serial += 82000L;
		for (FrontDomain dpd: dpDomains ) {
			org.javaforever.gatescore.shiroauth.verb.ListActive la = new org.javaforever.gatescore.shiroauth.verb.ListActive(dpd);
			FrontMethod m = la.generateControllerMethod();
			if (m!= null) {
				m.setSerial(serial);
				sList.add(m.getMethodStatementList());
				serial += 1000L;
			}
		}
		sl = UtilsMethodGenerator.generateSleepMethodStatements();
		sl.setSerial(serial);
		sList.add(sl);
		
		serial += 1000L;
		for (FrontDropdown dp : this.domain.getDropdownSet()) {
			sl = UtilsMethodGenerator.generateTranslateDomainMethodStatements(dp.getTarget());
			sl.setSerial(serial);
			sl.setIndent(1);
			sList.add(sl);
			serial += 1000L;
		}
		
		sList.add(new Statement(serial+82000L,1,"}"));
		sList.add(new Statement(serial+83000L,0,"}"));
		sList.add(new Statement(serial+84000L,0,"</script>"));
		sList.add(new Statement(serial+85000L,0,""));
		sList.add(new Statement(serial+86000L,0,"<style rel=\"stylesheet/scss\" lang=\"scss\">"));
		sList.add(new Statement(serial+87000L,0,"$bg:white;"));
		sList.add(new Statement(serial+88000L,0,"$dark_gray:#889aa4;"));
		sList.add(new Statement(serial+89000L,0,"$light_gray:#eee;"));
		sList.add(new Statement(serial+90000L,0,""));
		sList.add(new Statement(serial+91000L,0,".app-container{"));
		sList.add(new Statement(serial+92000L,0,"min-height: 100%;"));
		sList.add(new Statement(serial+93000L,0,"width: 100%;"));
		sList.add(new Statement(serial+94000L,0,"background-color: $bg;"));
		sList.add(new Statement(serial+95000L,0,"overflow: hidden;"));
		sList.add(new Statement(serial+96000L,0,".login-form {"));
		sList.add(new Statement(serial+97000L,1,"position: relative;"));
		sList.add(new Statement(serial+98000L,1,"width: 520px;"));
		sList.add(new Statement(serial+99000L,1,"max-width: 100%;"));
		sList.add(new Statement(serial+100000L,1,"padding: 160px 35px 0;"));
		sList.add(new Statement(serial+101000L,1,"margin: 0 auto;"));
		sList.add(new Statement(serial+102000L,1,"overflow: hidden;"));
		sList.add(new Statement(serial+103000L,0,"}"));
		sList.add(new Statement(serial+104000L,0,"}"));
		sList.add(new Statement(serial+105000L,0,"</style>"));

		return WriteableUtil.merge(sList);
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public FrontDomain getDomain() {
		return domain;
	}

	public void setDomain(FrontDomain domain) {
		this.domain = domain;
		this.title = domain.getProjectName();
		Set<FrontField> deniedFields = new TreeSet<>();
		deniedFields.add(domain.findFieldByFixedName("password"));
		deniedFields.add(domain.findFieldByFixedName("salt"));
		deniedFields.add(domain.findFieldByFixedName("loginFailure"));
		setDeniedFields(deniedFields);
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Set<FrontField> getDeniedFields() {
		return deniedFields;
	}

	public void setDeniedFields(Set<FrontField> deniedFields) {
		this.deniedFields = deniedFields;
	}
}
